package com.douwong.student.popuwindow;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.adapter.ScanIpAdapter;
import com.douwong.student.application.BaseApplication;
import com.douwong.student.factory.ThreadFactory;
import com.douwong.student.enums.E_CommandType;
import com.douwong.student.enums.E_Destination;
import com.douwong.student.model.LoginTeacherServiceInfo;
import com.douwong.student.model.TeacherOnline;
import com.douwong.student.socket.LTPServer;

import java.util.List;

/**
 * @autor yichao
 * @time 2017/3/3017:38
 * @des ${TODO}
 */
public class TeacherInfoPopuwindow extends PopupWindow {
    private static final String TAG = "TeacherInfoPopuwindow";
    private View contenView;
    private ListView scan_listview;
    private TextView scan_line_text,scan_line2_text,scan_cancel_text,scan_time_text;

    public TeacherInfoPopuwindow(final Activity activity, final List<TeacherOnline> teacherOnlineList) {

        LayoutInflater inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        contenView = inflater.inflate(R.layout.scan_ip_layout, null);
        initView();
        ScanIpAdapter scanIpAdapter=new ScanIpAdapter(activity,teacherOnlineList);
        scan_listview.setAdapter(scanIpAdapter);

        scan_time_text.setText("在线老师的信息");
        this.setContentView(contenView);
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0x00ffffff);
        this.setBackgroundDrawable(dw);
        scan_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //点击加入
                BaseApplication.temTeacherOnline = teacherOnlineList.get(position);

                ThreadFactory.getNormalPool().execute(new Runnable() {
                    @Override
                    public void run() {
                        LoginTeacherServiceInfo loginTeacherServiceInfo =new LoginTeacherServiceInfo();
                        loginTeacherServiceInfo.setStudentInfo(BaseApplication.sStudentOnline);
                        loginTeacherServiceInfo.setTeacherInfo(BaseApplication.temTeacherOnline);
                        LTPServer.createInstance(activity).sendMsg(loginTeacherServiceInfo, E_CommandType.serverLoginStudent, E_Destination.server,new int[]{0});

                    }
                });

                //  LTPServer.createInstance().sendMsg();


            }
        });
    }

    private void initView() {
        scan_listview = (ListView) contenView.findViewById(R.id.scan_listview);
        scan_line_text = (TextView) contenView.findViewById(R.id.scan_line_text);
        scan_line2_text = (TextView) contenView.findViewById(R.id.scan_line2_text);
        scan_cancel_text = (TextView) contenView.findViewById(R.id.scan_cancel_text);
        scan_time_text = (TextView) contenView.findViewById(R.id.scan_time_text);

    }


}
